<template>
	<view class="container">
		<view class="user-section " style="height: 320rpx;">
			<view class="bg-img" style="width: 100%;height: 100%;"><image style="height: 100%;" :src="'/static/shuijiao.jpg'" mode="scaleToFill"></image></view>
			<view class="user-section" style="height: 320rpx;">
				<view class="user-info-box" style="display: flex; align-items: center; height: 100%;padding: 20rpx;">
					<view style="width: 50%; height: 100rpx;padding-left: 16rpx;display: flex;align-items: center;"><text style="color: white;font-size: 36rpx;">吴斌</text></view>
					<view class="header-right">
						<view class="user-head" @click="headClick">
							<image
								:src="getUserAvatar()"
								mode="aspectFill"
								@error="
									'/static/mine/wxlogo.png';

								"
							></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="uni-list-back">
			<view class="slot-box item-view-header"></view>

			<uni-list>
				<uni-list-item>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="shiming()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_auth.png'"></image>
								<view class="text">实名认证</view>
							</view>
							<view class="text1">已认证</view>
						</view>
					</template>
				</uni-list-item>
				<uni-list-item>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="htauth()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_auth.png'"></image>
								<view class="text">合同认证</view>
							</view>
							<view class="text1">未认证</view>
						</view>
					</template>
				</uni-list-item>
				<uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="xiugaimima()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_pwd.png'"></image>
								<view class="text">修改登录密码</view>
							</view>
						</view>
					</template>
				</uni-list-item>

				<uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="genghuan()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_mobile.png'"></image>
								<view class="text">更换手机号</view>
							</view>
						</view>
					</template>
				</uni-list-item>
				<uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="dizhibu()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_address.png'"></image>
								<view class="text">地址簿</view>
							</view>
						</view>
					</template>
				</uni-list-item>
				
				 <!-- #ifdef APP-PLUS-->
				<uni-list-item>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="qingchu()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_cacha.png'"></image>
								<view class="text">清除缓存</view>
							</view>
							<view class="text1">{{ fileSizeString }}</view>
						</view>
					</template>
				</uni-list-item>
				<!-- #endif -->
			
			</uni-list>

			<view class="slot-box item-view-header"></view>
			<uni-list>
				<uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="fenxiang()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_share.png'"></image>
								<view class="text">分享</view>
							</view>
						</view>
					</template>
				</uni-list-item>
				<uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="gongneng()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_gongneng.png'"></image>
								<view class="text">功能介绍</view>
							</view>
						</view>
					</template>
				</uni-list-item>
				<uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="guanyu()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_about.png'"></image>
								<view class="text">关于我们</view>
							</view>
						</view>
					</template>
				</uni-list-item>
				<!-- <uni-list-item showArrow>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="yunshuxiye()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_about.png'"></image>
								<view class="text">运输协议</view>
							</view>
						</view>
					</template>
				</uni-list-item> -->
				<uni-list-item>
					<template v-slot:body>
						<view class="slot-box slot-text item-view" @click="gengxin()">
							<view class="item-view-left">
								<image class="image" :src="'/static/mine/setting_update.png'"></image>
								<view class="text">版本更新</view>
							</view>

							<view class="text1">{{ versionstr }}</view>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
			<view class="item-view-header"></view>
			<uni-list>
				<uni-list-item>
					<template v-slot:body>
						<view class="slot-box slot-text item-view item-view1" @click="lianxi()">
							<view class="item-view-center">
								<image class="image" :src="'/static/mine/order_detail_mobile.png'"></image>
								<view class="text">联系客服：</view>
								<view class="text2">{{ mobile }}</view>
							</view>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
			<view class="item-view-header"></view>
			<uni-list style="margin-top: 16rpx;">
				<uni-list-item>
					<template v-slot:body>
						<view class="slot-box slot-text item-view">
							<view class="item-view-bottom" @click="logout()">
								<view class="btn"><text>退出系统</text></view>
							</view>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
export default {
	components: {},
	mixins: [],
	data() {
		return {
			versionstr: '',
			fileSizeString: '0B',
			mobile: this.$serviceMobile
		};
	},
	onLoad() {
		const accountInfo = uni.getAppBaseInfo();
		this.versionstr = accountInfo.appVersion;
		// #ifdef APP-PLUS
		this.formatSize();
		// #endif
	},
	methods: {
		getUserAvatar() {
			if(this.check.isNull(getApp().globalData.userInfo.avatar)){
				return '/static/mine/wxlogo.png'
			}else{
				return getApp().globalData.userInfo.avatar;
			} 
		},
		headClick(){
			this.$util.redirectTo('/pages/mine/myInfo/myInfo');
		},
		shiming() {
			this.$util.redirectTo('/pages/mine/myAuth/myAuth');
		},
		htauth() {
			this.$util.redirectTo('/pages/mine/htAuth/htAuth');
		},
		xiugaimima() {
			this.$util.redirectTo('/pages/mine/password/password');
		},
		genghuan() {
			this.$util.redirectTo('/pages/mine/mobile/mobile');
		},
		dizhibu() {
			this.$util.redirectTo('/pages/mine/address/address');
		},
		qingchu() {
			this.clearCache();
		},
		fenxiang() {
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneSession',
				type: 0,
				href: 'http://uniapp.dcloud.io/',
				title: 'uni-app分享',
				summary: '我正在使用HBuilderX开发uni-app，赶紧跟我一起来体验！',
				imageUrl: 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-uni-app-doc/d8590190-4f28-11eb-b680-7980c8a877b8.png',
				success: function(res) {
					console.log('success:' + JSON.stringify(res));
				},
				fail: function(err) {
					console.log('fail:' + JSON.stringify(err));
				}
			});
		},
		gongneng() {
			// this.$util.redirectTo('/pages/mine/gongneng/gongneng');
			this.$util.redirectTo('/pages/webview/webview', { type: '4' });
		},
		guanyu() {
			// this.$util.redirectTo('/pages/mine/about/about');
			this.$util.redirectTo('/pages/webview/webview', { type: '3' });
		},
		yunshuxiye() {
			// this.$util.redirectTo('/pages/mine/agreement/agreement');
			this.$util.redirectTo('/pages/webview/webview', { type: '5' });
		},
		gengxin() {},
		lianxi() {
			uni.makePhoneCall({
				phoneNumber: this.$serviceMobile,
				success: () => {
					console.log('成功拨打电话');
				}
			});
		},
		formatSize() {
			// #ifdef APP-PLUS
			let that = this;
			plus.cache.calculate(function(size) {
				let sizeCache = parseInt(size);
				if (sizeCache == 0) {
					that.fileSizeString = '0B';
				} else if (sizeCache < 1024) {
					that.fileSizeString = sizeCache + 'B';
				} else if (sizeCache < 1048576) {
					that.fileSizeString = (sizeCache / 1024).toFixed(2) + 'KB';
				} else if (sizeCache < 1073741824) {
					that.fileSizeString = (sizeCache / 1048576).toFixed(2) + 'MB';
				} else {
					that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + 'GB';
				}
			});
			// #endif
			
		},
		clearCache() {
			let that = this;
			let os = plus.os.name;
			if (os == 'Android') {
				let main = plus.android.runtimeMainActivity();
				let sdRoot = main.getCacheDir();
				let files = plus.android.invoke(sdRoot, 'listFiles');
				let len = files.length;
				for (let i = 0; i < len; i++) {
					let filePath = '' + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径
					plus.io.resolveLocalFileSystemURL(
						filePath,
						function(entry) {
							if (entry.isDirectory) {
								entry.removeRecursively(
									function(entry) {
										//递归删除其下的所有文件及子目录
										uni.showToast({
											title: '缓存清理完成',
											duration: 2000
										});
										that.formatSize(); // 重新计算缓存
									},
									function(e) {
										console.log(e.message);
									}
								);
							} else {
								entry.remove();
							}
						},
						function(e) {
							console.log('文件路径读取失败');
						}
					);
				}
			} else {
				// ios暂时未找到清理缓存的方法，以下是官方提供的方法，但是无效，会报错
				plus.cache.clear(function() {
					uni.showToast({
						title: '缓存清理完成',
						duration: 2000
					});
					that.formatSize();
				});
			}
		},
		logout() {
			const that = this
			uni.showModal({
				title: '提示',
				content: '是否退出',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
						that.$util.redirectToHome(true);
					} else {
						
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
@import '../public/css/setting.scss';
</style>
